﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<title>Embedded Resource Files</title>
		<link href="bootstrap.min.css" type="text/css" rel="stylesheet" />
	</head>

	<body>

		<div class="document-contents">

			<h3 id="DocIntro">Introduction</h3>
			<p>In a web application, there are javascript, css, xml... files used by 
clients. They are generally added to a web project and published as seperated files. 
Sometimes, we need to package some of these files into an assembly (a class library project, 
a dll file) and distribute as embedded resource files in the 
assembly. ASP.NET Boilerplate provides an infrastructure to make this easy.</p>

			<h3 id="DocCreateFiles">Create embedded files</h3>
			<p>We first should create a resource file and mark it as <strong>embedded 
resource</strong>. Any assembly can contain embedded resource files. Assume that we have an assembly named 
'Abp.Zero.Web.UI.Metronic.dll' and it contains javascripts, css and image files:</p>

			<p>
				<img alt="Embedded Javascript Files" height="309" src="images/embedded-resource-sample-dll.png" width="246" />
			</p>
			<p>We want to make these files usable in a web application. First, we 
should make <strong>build action</strong> to <strong>embedded resource</strong> 
for files we want to expose. I select <strong>metronic.js</strong> file, go to properties window 
(F4 as shortcut) and change it.</p>
			<p>
				<img alt="Mark file as embedded resource" height="350" src="images/embedded-resource-sample-file.png" width="366" />
			</p>
			<p>
You should change build action to <strong>embedded resource</strong> for <strong>all</strong> 
files you want to use in a web application.</p>

			<h3 id="DocExposeFiles">Expose embedded files</h3>
			<p>ASP.NET Boilerplate makes it easy to expose embedded resource files. It's a 
single line of code:</p>

			<pre lang="js">WebResourceHelper.ExposeEmbeddedResources("AbpZero/Metronic", Assembly.GetExecutingAssembly(), "Abp.Zero.Web.UI.Metronic");</pre>
			<p>This code generally stands in Initialize method of the
				<a href="/Pages/Documents/Module-System">module</a>. Let's explain parameters:</p>
			<ul>
				<li>First parameter defines <strong>root folder</strong> for files. It 
	matches to root namespace.</li>
				<li>Second parameter defines the <strong>Assembly</strong> contains files. 
	In this example, I passed the assembly contains this code. But you can pass 
	any assembly contains embedded resources.</li>
				<li>And the last one defines <strong>root namespace</strong> of files in the 
	assembly. This is the 'default namespace' plus 'folders in the assembly'. 
	Default namespace is 
	generally same as assembly's name but can be changed in properties of 
	the assembly. Here, default namespace is Abp (I changed it), so Metronic 
	folder's namespace is '<strong>Abp</strong>.Zero.Web.UI.Metronic'.</li>
			</ul>

			<h3 id="DocConsumeFiles">Consume embedded files</h3>
			<p>Consuming embedded files is straightforward:</p>
			<pre lang="html">&lt;script type=&quot;text/javascript&quot; src=&quot;<strong>~/AbpZero/Metronic/</strong>assets/global/scripts/metronic.js&quot;&gt;&lt;/script&gt;</pre>
			<p>ASP.NET Boilerplate understands this is an embedded file and gets file 
from dll exposed before. While it simply works, you can use <strong>IncludeScript</strong> HtmlHelper 
extension method of ASP.NET Boilerplate in a razor view:</p>
			<pre lang="cs">@Html.IncludeScript(&quot;~/AbpZero/Metronic/assets/global/scripts/metronic.js&quot;)</pre>
			<p>This will produce the same script tag as shown below:</p>
			<pre lang="html">&lt;script src=&quot;/AbpZero/Metronic/assets/global/scripts/metronic.js<strong>?v=635438748506909100</strong>&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
			<p>Only difference is the <strong>v=635438748506909100</strong> parameter. This 
prevents <strong>faulty caching</strong> of the script by browsers. This value 
changes only when your dll re-built (actually, it's the last write time of the 
file) and browser does not cache if it changes. So, using IncludeScript is the
				<strong>suggested</strong> way. It also works for non-embedded, <strong>physical</strong> files. There is also <strong>IncludeStyle</strong> method for 
css files.</p>

		</div>

	</body>

</html>